import { observable, action } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import { WeaTools } from 'ecCom';
import {message,Modal} from 'antd';
const confirm = Modal.confirm;
import {toJS} from "mobx"
import * as Apis from "../apis/project"
import * as Common_Apis from '../apis/index'
import {ShareStore} from './shareStore'
import {TaskInfoStore} from './task/taskInfoStore'
import {ExchangeStore } from "./exchangeStore"
import {RelateListStore} from './taskListStore'

export  class TaskListStoreNew{

    //任务列表
    @observable listVisible = false;
    @observable prjid = "";
    @observable taskListTableStore = new TableStore({dataHandle: (datas) => {  //任务列表
		datas.forEach((data) => {
		  if (typeof(data.subListspan) == 'string') {
			data.subListspan = data.subListspan ? JSON.parse(data.subListspan) : undefined;
		  }
		});
		return datas;
	  }});
	@observable taskListform = new WeaForm();
	@observable taskListquickform = new WeaForm();
	@observable taskListTabs = [];
	@observable taskListSearchParams = {
		version:"0"
	};
	@observable taskListQuickitems = [];
	@observable taskListRight={
		hasRight:false,
		verified:false
    }
	@observable taskInfoStore = new TaskInfoStore();
	@observable exchangeStore = new ExchangeStore();
    @observable prjLogTableStore = new TableStore();  //日值
    @observable relateListStore = new RelateListStore();
    
    @observable exchangeform = new WeaForm();
	@observable exchangeContent = {}  //相关交流内容
	
	@observable shareTableStore =  new TableStore(); //共享
	@observable shareStore = new ShareStore();
	@observable isShowShare = false;
	@observable shareRight={
		hasRight:false,
		verified:false
    }
    @observable rightMenu  =[];
    // @observable prjCardStore = new PrjCardStore();
	
    @action 
	reLoad = (tableStore) => {
        tableStore.getDatas(tableStore.dataKey, tableStore.current,tableStore.pageSize,tableStore.sortParams)
    }
    showTaskLiskModal=(bool,id)=>{
        this.listVisible = bool;
        this.prjid = id;
        if(bool){
            this.getPrjTaskList();
			this.getPrjTaskCondition();
			this.getPrjTaskVersion();
        }
    }
    //任务列表
	getPrjTaskList = (params={}) =>{
		let newParams = {...toJS(this.taskListSearchParams),...toJS(this.taskListform.getFormParams()),...toJS(this.taskListquickform.getFormParams()),prjid:this.prjid,...params};
		if(newParams.version == "0"){newParams.version = ""}
		Apis.getPrjTaskList(newParams).then(data=>{
			if(!data.isright && typeof(data.isright) !== "undefined"){
				this.taskListRight = {
					hasRight:data.isright,
					verified:true
				};
			}else{
				this.taskListRight = {
					hasRight:true,
					verified:true
				};
				this.taskListTableStore.getDatas(data.sessionkey,  1);
				this.rightMenu = data.rightMenus;
				this.taskListSearchParams = params.version==""?{version:"0"}:{...this.taskListSearchParams,...params};	
			};
			this.loading = false;
		})
	}
	//任务列表-condition
	getPrjTaskCondition=()=>{
		this.taskListform = new WeaForm();
		this.taskListquickform = new WeaForm();
		this.condition = [];
		this.taskListQuickitems = [];
		this.taskListSearchParams = {version: this.taskListSearchParams.version};	
		Common_Apis.getTaskCondition({conditiontype :"prjtasklist",prjid:this.prjid}).then(data=>{
			this.condition = data.condition;
			this.taskListQuickitems = data.quickitmes;
			this.taskListform && !this.taskListform.isFormInit && this.taskListform.initFormFields(data.condition);
			this.taskListquickform && !this.taskListquickform.isFormInit && this.taskListquickform.initFormFields(data.quickitmes);
		})
	}
	getPrjTaskVersion=()=>{
		Apis.getPrjTaskVersion({prjid:this.prjid}).then(data=>{
			this.taskListTabs = data;
		})
	}

}